package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.stark.downloader.Downloader;
import com.stark.downloader.FailCause;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityImgDetailBinding;
import stark.common.bean.StkResBean;

public class ImgDetailActivity extends BaseAc<ActivityImgDetailBinding> {

    public static StkResBean stkResBean;

    @Override
    protected int onCreate() {
        return R.layout.activity_img_detail;
    }

    @Override
    protected void initView() {
        mDataBinding.ivImgDetailBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvDownload.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvDownload://下载
                Downloader.newTask(mContext)
                        .url(stkResBean.getUrl())
                        .saveToPublic(true)
                        //Android10及以上，保存到外部公共存储空间需提供文件名称
                        .fileName(System.currentTimeMillis() + ".jpg")
                        .start(new Downloader.ICallback() {
                            @Override
                            public void onStart(int downloadTaskId) {

                            }

                            @Override
                            public void onProgress(long currentOffset, long totalLength, int percent) {

                            }

                            @Override
                            public void onComplete(@NonNull Uri uri) {
                                ToastUtils.showShort(getString(R.string.download_suc));
                            }

                            @Override
                            public void onFail(FailCause cause) {
                                ToastUtils.showShort(R.string.download_failure);
                            }
                        });
                break;
        }
    }

    @Override
    protected void initData() {
        Glide.with(mContext).load(stkResBean.getUrl()).into(mDataBinding.ivImg);
    }
}